home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / pwd / c / pwdread < prev   
Text File  |  1996-11-09  |  2KB  |  96 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/pwd/c/RCS/pwdread,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: pwdread,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: pwdread,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* pwd.c.pwdread. Internal password-file reading functions.
  18.  
  19.    Modified from the original c.getpw by Nick Burrett, 13 October 1996.  */
  20.  
  21. #include <errno.h>
  22. #include <limits.h>
  23. #include <stddef.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <pwd.h>
  28.  
  29. /* p_pstrcp() */
  30.  
  31. static char *
  32. p_pstrcp (char **lp)
  33. {
  34.   register char *l = *lp, *r = l;
  35.  
  36.   while ((*l != ':') && *l)
  37.     l++;
  38.   if (*l)
  39.     *l++ = 0;
  40.   *lp = l;
  41.   return (r);
  42. }
  43.  
  44. /* p_pdecode() */
  45.  
  46. static void
  47. p_pdecode (char *line, struct passwd *passwd)
  48. {
  49.   char *lp;
  50.  
  51.   if (!line || !passwd)
  52.     return;
  53.  
  54.   lp = line;
  55.  
  56.   passwd->pw_name = p_pstrcp (&lp);
  57.   passwd->pw_passwd = p_pstrcp (&lp);
  58.   passwd->pw_uid = atoi (p_pstrcp (&lp));
  59.   passwd->pw_gid = atoi (p_pstrcp (&lp));
  60.   passwd->pw_gecos = p_pstrcp (&lp);
  61.   passwd->pw_dir = p_pstrcp (&lp);
  62.   passwd->pw_shell = p_pstrcp (&lp);
  63. }
  64.  
  65. /* Read one entry from the given stream.  */
  66. struct passwd *
  67. __pwdread (FILE *stream, struct passwd *ppwd)
  68. {
  69.   char buf[256], *bp;
  70.  
  71.   if (stream == NULL)
  72.     return 0;
  73.  
  74.   /* Get a line, skipping past comment lines.  */
  75.   do
  76.     if (fgets (buf, sizeof (buf) - 1, stream) == 0)
  77.     /* if (getline (buf, sizeof (buf) - 1, stream) == -1) */
  78.       return 0;
  79.   while (buf[0] == '#');
  80.  
  81.   /* Take the line and convert the newline into a zero terminated
  82.      string.  */
  83.   bp = buf;
  84.   while (*bp)
  85.     bp++;
  86.   if (*--bp != '\n')
  87.     return 0;
  88.   *bp = 0;
  89.  
  90.   /* Decode the line.  */
  91.   p_pdecode (buf, ppwd);
  92.   return ppwd;
  93. }
  94.  
  95.  
  96.